﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using DocumentsTagger.DM;

namespace DocumentsTagger.UI.Model
{
    /// <summary>
    /// This class is a Model for UI puporses that will hold the UI part of the checkable tag in the listboxs
    /// </summary>
    public class TagUIModel
    {
        #region members
        private readonly Tag r_tag;
        #endregion

        #region properties
        /// <summary>
        /// gets or sets the name of the tag
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// gets or sets if the tag is checked
        /// </summary>
        public bool IsChecked { get; set; }

        /// <summary>
        /// gets the underlying tag object
        /// </summary>
        public Tag Tag { get { return r_tag; } }
        #endregion

        #region ctor
        /// <summary>
        /// creates the tag ui part
        /// </summary>
        /// <param name="tag">the underlying tag object</param>
        public TagUIModel(Tag tag)
        {
            this.r_tag = tag;
            this.IsChecked = false;
            this.Name = tag.Name;
        }
        #endregion

        #region methods
        /// <summary>
        /// ToString implementation
        /// </summary>
        /// <returns>the name of the tag</returns>
        public override string ToString()
        {
            return this.Name;
        }

        /// <summary>
        /// Overrides the Equals function
        /// </summary>
        /// <param name="obj">an object to compare</param>
        /// <returns>true if object is of the same tag name as this one.</returns>
        public override bool Equals(object obj)
        {
            bool equals = false;
            if (obj is TagUIModel)
            {
                equals = this.Name.Equals(((TagUIModel)obj).Name);
            }

            return equals;
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }
        #endregion
        
    }
}
